package com.ucombuy.getaway.filter;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by yaosheng on 2021/3/12.
 */
@Slf4j
@Component
public class AccessLogFilter extends AbstractPostZuulFilter{

    @Override
    protected Object cRun() {

        HttpServletRequest request = context.getRequest ();
        //从PreRequestFilter中获取设置的请求时间戳
        Long startTime = (Long)context.get ("startTime");
        String uri = request.getRequestURI ();
        Long duration = System.currentTimeMillis () - startTime;

        //从网关通过的请求都会在日志中打印
        log.info ("uri : {},duration : {}",uri,duration);
        return Success ();
    }

    @Override
    public int filterOrder() {
        return 0;
    }
}
